package com.ys.controller.web.business;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ys.entity.business.TpBoutiqueDiscount;

import lombok.AllArgsConstructor;
import lombok.Data;

@Controller
@RequestMapping("/web/business/tpBoutiqueDiscount")
public class WebTpBoutiqueDiscountController {
	
	/*
	 * 新增
	 */
    @RequiresPermissions("tpBoutiqueDiscount:setting")
	@GetMapping("/toSetting")
	public String toSetting(Model model, HttpServletRequest request, HttpServletResponse response){
		
    	List<SettingDto.PriceDto> priceArr = new ArrayList<SettingDto.PriceDto>();
    	List<TpBoutiqueDiscount> listEntity = new TpBoutiqueDiscount().queryList();
    	for(TpBoutiqueDiscount entity : listEntity) {
    		BigDecimal amount = entity.getAmount();
    		BigDecimal discount = entity.getDiscount();
    		priceArr.add(new SettingDto.PriceDto(amount, discount));
    	}
    	
    	SettingDto dto = new SettingDto(priceArr);
    	model.addAttribute("dto", dto);

		return "business/tpBoutiqueDiscount/toSetting";
	}
    @Data
    @AllArgsConstructor
    public static class SettingDto {
    	private List<PriceDto> priceArr; // 价格数组

        @Data
        @AllArgsConstructor
        public static class PriceDto {
        	private BigDecimal amount; // 调拨价格
        	private BigDecimal discount; //  折扣，如97%，则填写为0.97
        }
    }
}
